/*
 * Copyright (c) 2009-2020 Weasis Team and other contributors.
 *
 * This program and the accompanying materials are made available under the terms of the Eclipse
 * Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0, or the Apache
 * License, Version 2.0 which is available at https://www.apache.org/licenses/LICENSE-2.0.
 *
 * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
 */
package org.weasis.dicom.sr;

import org.dcm4che3.data.Attributes;
import org.dcm4che3.data.Tag;
import org.weasis.dicom.codec.DicomMediaIO;
import org.weasis.dicom.codec.DicomSpecialElement;
import org.weasis.dicom.macro.Code;

public class SRSpecialElement extends DicomSpecialElement {

  public SRSpecialElement(DicomMediaIO mediaIO) {
    super(mediaIO);
  }

  @Override
  protected void initLabel() {
    /*
     * DICOM PS 3.3 - 2011 - C.17.3 SR Document Content Module
     *
     * Concept Name Code Sequence: mandatory when type is CONTAINER or the root content item.
     */
    StringBuilder buf = new StringBuilder(getLabelPrefix());

    Attributes dicom = ((DicomMediaIO) mediaIO).getDicomObject();
    Attributes item = dicom.getNestedDataset(Tag.ConceptNameCodeSequence);
    if (item != null) {
      Code code = new Code(item);
      buf.append(code.getCodeMeaning());
    }
    label = buf.toString();
  }
}
